package com.server.service;



import com.client.service.LoginService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.server.store.context.UserManager;
import com.shared.context.User;

/**
 * Implémentation du service de login
 * @author queyroi
 *
 */
@SuppressWarnings("serial")
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService{

	//@Override
	public User check(String name, String password) throws IllegalArgumentException{
		
		UserManager userManager = new UserManager();
		
		if (name != null && password!=null) {		
			
			if(userManager.getList().isEmpty()){		
				User admin = new User("admin","admin",true);
				userManager.save(admin);
			}
			
			User user = userManager.get(name, password);
			getThreadLocalRequest().getSession().setAttribute("user",user);
			return user;
		}
		throw new IllegalArgumentException("Mauvais nom ou mot de passe");
	}
	
	
}
